package com.bwie.controller;

import com.bwie.common.domain.Shop;
import com.bwie.common.domain.vo.ShopVo;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.service.ShopService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author：Minxiao Hao
 * @Description:
 * @name：ShopController
 * @Date：2024/11/4 10:40
 */
@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    /**
     * 列表 分页 每页展示三条数据
     * @param shopVo
     * @return
     */
    @PostMapping("/findShopList")
    public PageResult<ShopVo> findShopList(ShopVo shopVo){
        PageHelper.startPage(shopVo.getPageNum(),shopVo.getPageSize());
        List<ShopVo> list = shopService.findShopList(shopVo);
        PageInfo pageInfo = new PageInfo(list);
        PageResult pageResult = PageResult.toPageResult(pageInfo.getTotal(),list);
        return pageResult;
    }

    /**
     * 添加
     * @param shop
     * @return
     */
    @PostMapping("/insertShop")
    public Result insertShop(@RequestBody Shop shop){
        shopService.insertShop(shop);
        Result result = Result.success();
        return result;
    }
}
